<template>
  <div style="color: #666">
    <div style="margin: 10px 0">
      <el-input style="width: 300px" placeholder="请输入姓名..." suffix-icon="el-icon-search" class="ml-5"
                v-model="name"></el-input>
      <el-button class="ml-5" type="primary" @click="seachKehu">搜索</el-button>
      <el-button @click="resetForm">重置</el-button>
    </div>

    <div style="margin: 10px 0">
      <div style="padding: 10px 0;border-bottom: 1px dashed #ccc" v-for="item in tableData" :key="item.id">
        <div class="pd-10" style="font-size: 20px;color: #42b983;cursor: pointer" @click="$router.push('/front/forumDetail?id='+item.id)">{{item.title}}</div>
        <div style="font-size: 14px;margin-top: 10px; display: flex; justify-content: flex-end;">
          <i class="el-icon-user-solid"></i><span>{{item.name}}</span>
          <i class="el-icon-time" style="margin-left: 10px"></i><span>{{item.addtime}}</span>
        </div>
      </div>


    </div>

    <div style="padding: 10px 0">
      <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="pageNum"
          :page-sizes="[5, 10,15,20]"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
      </el-pagination>
    </div>

  </div>
</template>

<script>

import request from "@/utils/request";
export default {
  name: "Forum",
  data(){
    return {
      tableData: [],
      total: 0,
      pageNum: 1,
      pageSize: 5,
      name: "",
      form:{
        id:"",
        title:"",
        name:"",
        content:"",
        praise:"",
        tread:"",
        addtime:""
      },
      dialogFormVisible: false,
      imageUrl: '',
      headerBg: 'headerBg',
      multipleSelection: []
    }
  },
  created() {
    this.load()
  },
  methods: {

    delbath(){
      let ids=this.multipleSelection.map(v =>v.id)
      request.post("forum/deletebatch",ids).then(res => {
        if (res.code == "200") {
          this.load()
          this.$message.success("删除成功")
        } else {
          this.$message.error("删除失败")
        }
      })
    },
    deletekehu(id) {
      console.log(id)
      request.post("forum/delete",id).then(res => {
        if (res.code == "200") {
          this.load()
          this.$message.success("删除成功")
        } else {
          this.$message.error("删除失败")
        }
      })
    },
    updatekehu(row){
      this.form=row
      this.dialogFormVisible=true
    },
    saveKehu(){
      this.dialogFormVisible = false
      if (this.form.id){
        request.post("forum/update",this.form).then(res =>{
          if (res.code=="200"){
            this.load()
            this.$message.success("修改信息成功")
          }else {
            this.$message.error("修改信息失败")
          }
        })

      }else {
        request.post("forum",this.form).then(res =>{
          if (res.code=="200"){
            this.load()
            this.$message.success("新增成功")
          }else {
            this.$message.error("新增失败")
          }
        })
      }
    },
    openKehudialog(){
      this.form={}
      this.dialogFormVisible=true
    },
    resetForm() {
      this.name = ""
      this.load()
    },
    seachKehu() {
      this.load()
    },
    handleCurrentChange(data) {
      this.pageNum = data
      this.load()
    },
    handleSizeChange(data) {
      this.pageSize = data
      this.load()
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    load() {
      request.get("forum/page", {
        params: {
          pageNum: this.pageNum,
          pageSize: this.pageSize,
          name: this.name
        }
      }).then(res => {
        if (res.code=="200"){
          this.tableData = res.data.records
          this.total = res.data.total
        }

      })
    }
  }

}
</script>

<style scoped>

</style>